package com.itqf.quartz03;

import org.quartz.*;
import org.quartz.impl.StdSchedulerFactory;

/**
 * @Description: CronTrigger
 * @Company: 千锋互联
 * @Author: 李丽婷
 * @Date: 2021/1/26
 * @Time: 上午11:05
 */
public class QuartzDemo02_CronTrigger {

    public  static  void  main(String[]args){
        //1.jobDetail
        JobDetail jobDetail = JobBuilder.newJob(MyBackupDBJob.class)
                .withIdentity("myJob").build();
        //传值   业务数据
        jobDetail.getJobDataMap().put("name","赵人和");

        //2.trigger
        //2021年每个月的每一个星期二的11点-12点每秒都执行 cron
        //英文
        CronTrigger cronTrigger = TriggerBuilder.newTrigger()
                .withSchedule(CronScheduleBuilder.cronSchedule("*/10 * 11-12 ? * 3 2021"))
                .withIdentity("myCronTrigger")
                .build();

        //3.scheduler
        SchedulerFactory schedulerFactory = new StdSchedulerFactory();
        try {
            Scheduler scheduler = schedulerFactory.getScheduler();

            //4.注册
            scheduler.scheduleJob(jobDetail,cronTrigger);
            //5.开启
            scheduler.start();

        } catch (SchedulerException e) {
            e.printStackTrace();
        }



    }


}
